<template>
    <div class = "accounting">
        <div class = "page-top" v-if="this.$store.state.options.user.oda.notice != null">
            <dl class = "notice">
                <dt><img src = "../../../static/images/notice-red-mini.png" /></dt>
                <dd @click = "$router.push('/public/message-detail?id=' + $store.state.options.user.oda.notice.id)">{{
                                                                                                                    $store.state.options.user.oda.notice.title
                                                                                                                    }}
                </dd>
            </dl>
        </div>
        <van-tabs v-model = "tabs.index" color = "#00CC00" class = "order-list-items">
            <van-tab title = "待确认">
                <van-list v-model = "collectAccounting.loading" :finished = "collectAccounting.finished"
                          finished-text = "没有更多了" @load = "onLoad(collectAccounting.textType)">
                    <normal-order-list v-for = "(item, index) in collectAccounting.dataset" :key = "index"
                                       :ibase = "item.base" :dataset = "item.items"
                                       :textType = "collectAccounting.textType" class = "el-item" />
                </van-list>
            </van-tab>
            <van-tab title = "已确认">
                <van-list v-model = "confirmAccounting.loading" :finished = "confirmAccounting.finished"
                          finished-text = "没有更多了" @load = "onLoad(confirmAccounting.textType)">
                    <normal-order-list v-for = "(item, index) in confirmAccounting.dataset" :key = "index"
                                       :ibase = "item.base" :dataset = "item.items"
                                       :textType = "confirmAccounting.textType" class = "el-item" />
                </van-list>
            </van-tab>
        </van-tabs>
        <tab-group :dataset = "navButtonGroup" identity = "6" index = "0" />
    </div>
</template>

<script>
    import {Tab, Tabs, List} from 'vant';

    import NormalOrderList from '../../components/currency/order-item/normal-list-platform-manage.vue';
    import TabGroup from "../../components/currency/tab/tab.vue";

    export default {
        name: 'AccountingIndex',
        components: {
            [Tab.name]: Tab, [Tabs.name]: Tabs, [List.name]: List,
            NormalOrderList, TabGroup
        },
        data() {
            return {
                tabs: {
                    index: 0
                },
                navButtonGroup: [
                    {
                        name: "订单", route: {path: '/accounting/index'}
                    },
                    {
                        name: "报价管理", route: {path: '/accounting/quoted-price-manage'}
                    },
                    {
                        name: "个人中心", route: {path: '/accounting/personal-center'}
                    },
                    {
                        name: "个人中心", route: {path: '/accounting/personal-center'}
                    }
                ],
                collectAccounting: {
                    loading: false,
                    finished: false,
                    textType: 'collectAccounting',
                    page: 0,
                    list_rows: 10,
                    dataset: []
                },
                confirmAccounting: {
                    page: 0,
                    list_rows: 10,
                    loading: false,
                    finished: false,
                    textType: 'confirmAccounting',
                    dataset: []
                }
            }
        },
        mounted() {
            this.tabs.index = this.$route.query.index;
        },
        methods: {
            getOrderList(items) {
                var that = this;
                var status = '';
                switch (items.textType) {
                    case 'collectAccounting':
                        status = 7;
                        break;
                    case 'confirmAccounting':
                        status = 6;
                        break;
                }
                var url = '/api/home/order/getlist';
                var param = {
                    utype: 3,
                    page: items.page,
                    list_rows: items.list_rows,
                    status: status,
                    groupid: 1,
                    token: that.$store.state.options.user.token
                };
                var detail = [];
                this.$util.postRequestInterface(url, param, (res) => {
                    items.page = items.page + 1;
                    if (res.data == '') {
                        items.loading = false;
                        items.finished = true;
                    } else {
                        for (let i of res.data.data) {
                            for (let x of i.detail) {
                                detail.push({
                                    title: x.garbagename,
                                    // number: x.weighting_method == 1 ? x.weighting_num : '',
                                    // weight: x.weighting_method == 0 ? x.weighting_num : '',
                                    number: x.weighting_num,
                                    unit: x.danweiming,
                                    time: that.$moment(i.create_time * 1000).format('YYYY-MM-DD HH:mm:ss'),
                                })
                            }
                            items.dataset.push({
                                base: {
                                    id: i.id,
                                    number: i.ordernumber,
                                    amount: i.price,
                                    // protect: i.isbaozhi,
                                    price: i.price
                                },
                                items: detail
                            });
                            detail = []
                        }
                        // // 加载状态结束
                        items.loading = false;
                        // // 数据全部加载完成
                        if (items.dataset.length >= res.data.count) {
                            items.finished = true;
                        }
                    }
                })
            },
            onLoad(textType) {
                switch (textType) {
                    case 'collectAccounting':
                        this.getOrderList(this.collectAccounting);
                        break;
                    case 'confirmAccounting':
                        this.getOrderList(this.confirmAccounting);
                        break;
                }
            }
        }
    }
</script>

<style lang = 'scss' scoped>
    .page-top {
        width: 100%;
        height: 3rem;
        position: relative;

        .notice {
            position: absolute;
            top: 0rem;
            width: 100%;
            margin: 0rem;
            padding: 0.7rem 1rem;
            display: flex;
            background: rgba(255, 247, 209, 1);
            z-index: 1;
            box-sizing: border-box;

            dt {
                padding-right: 1rem;

                img {
                    width: 1.4rem;
                }
            }

            dd {
                white-space: nowrap;
                flex: 1;
                margin: 0rem;
                padding: 0rem;
                color: #FF9000;
                font-size: 1.3rem;
            }
        }
    }

    .order-list-items {

        .el-item {
            padding: 0.5rem 1rem 0rem;
        }
    }

</style>
